package com.aidong.applog.action;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;

import com.aidong.activity.entity.MstCampaign;
import com.aidong.applog.biz.TrnDownloadLogBiz;
import com.aidong.applog.entity.DownloadLog;
import com.aidong.util.PageUtil;
import com.aidong.util.ReadPropertiesUtil;
import com.opensymphony.xwork2.ModelDriven;

/**
 * 下载APP
 * 
 * @author java
 * @version 1.0 2015.6.25
 */
@ParentPackage("json")
@Namespace("/")
public class TrnDownloadLogAction implements ModelDriven<DownloadLog> {
	private DownloadLog downlog;

	@Override
	public DownloadLog getModel() {
		if (downlog == null) {
			downlog = new DownloadLog();
		}
		return downlog;
	}

	@Autowired
	private TrnDownloadLogBiz trnDownloadLogBiz;

	/**
	 * app下载
	 * 
	 * @return
	 */
	@Action(value = "downloadApp")
	public void downloadApp() {
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpServletResponse response = ServletActionContext.getResponse();
		try {
			String header = request.getHeader("user-agent");
			if (header.toLowerCase().indexOf("micromessenger") > -1) {
				request.getRequestDispatcher("/weixin/index.jsp").forward(request, response);
				//response.sendRedirect(request.getContextPath() + "/weixin/index.jsp");
			}else{
				DownloadLog dl = new DownloadLog();
				dl.setHeadInfo(header);
				trnDownloadLogBiz.addAppDownloadMsg(dl);
				response.sendRedirect(request.getContextPath() + "/weixin/apk/ailicai-2.3.1.11400-CPA8.apk");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void setTrnDownloadLogBiz(TrnDownloadLogBiz trnDownloadLogBiz) {
		this.trnDownloadLogBiz = trnDownloadLogBiz;
	}
}
